package com.keba.lamp.ai.controller;

import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.keba.basic.base.R;
import com.keba.basic.interfaces.echo.EchoService;
import com.keba.basic.utils.BeanPlusUtil;
import com.keba.lamp.ai.service.AiCustomerService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import com.keba.basic.base.controller.SuperController;
import com.keba.lamp.ai.service.AiApiKeyService;
import com.keba.lamp.ai.entity.AiApiKey;
import com.keba.lamp.ai.vo.save.AiApiKeySaveVO;
import com.keba.lamp.ai.vo.update.AiApiKeyUpdateVO;
import com.keba.lamp.ai.vo.result.AiApiKeyResultVO;
import com.keba.lamp.ai.vo.query.AiApiKeyPageQuery;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * apikey管理
 * </p>
 *
 * @author twg
 * @date 2025-03-02 19:15:52
 * @create [2025-03-02 19:15:52] [twg] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/aiApiKey")
@Tag(name = "apikey管理")
public class AiApiKeyController extends SuperController<AiApiKeyService, Long, AiApiKey
        , AiApiKeySaveVO, AiApiKeyUpdateVO, AiApiKeyPageQuery, AiApiKeyResultVO> {
    private final EchoService echoService;

    private final AiCustomerService aiCustomerService;

    @Override
    public EchoService getEchoService() {
        return echoService;
    }

    @Override
    public void handlerResult(IPage<AiApiKeyResultVO> page) {
        page.getRecords().forEach(item -> {
            item.setApiKey(DesensitizedUtil.mobilePhone(item.getApiKey()));
            item.getEchoMap().putIfAbsent("customerId", aiCustomerService.getById(item.getCustomerId()).getName());
        });
    }
}


